﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Resources;
using System.Text;
using System.Windows.Forms;

namespace PMQLNhaHang.CustomControl
{
    class exPictureBox : PictureBox
    {
        private int _idTable;     //ID của table
        private bool _isActive;   //1 Nếu Đang hoạt động ( có bàn ăn )
        private string _nameTable;//Tên của table vẽ lên trên Icon
        private Image _imgClick; //ảnh khi click
        private Image _imgUnclick;//ảnh khi không click

        public string NameTable
        {
            get { return _nameTable; }
            set { _nameTable = value; }
        }
        public int IdTable
        {
            get { return _idTable; }
            set { _idTable = value; }
        }
        public Image ImgClick
        {
            get { return _imgClick; }
            set { _imgClick = value; }
        }
        public Image ImgUnclick
        {
            get { return _imgUnclick; }
            set { _imgUnclick = value; }
        }
        public bool IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }

        public exPictureBox()
        {
            ResourceManager rm = new ResourceManager(typeof(exPictureBox));
            _imgUnclick = (Image)rm.GetObject("UnClick");
            _imgClick = (Image) rm.GetObject("Click");
            IsActive = false;
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            if(IsActive)
            {
                pe.Graphics.DrawImage(_imgClick,0,0);
            }
            else
            {
                pe.Graphics.DrawImage(_imgUnclick, 0, 0);
            }
            using (Font myfont = new Font("Arial", 10,FontStyle.Bold))
            {
                int top = pe.ClipRectangle.Height - (int)pe.Graphics.MeasureString(NameTable, myfont).Height-4;
                int left = pe.ClipRectangle.Width/2 - (int) pe.Graphics.MeasureString(NameTable, myfont).Width/2;
                pe.Graphics.DrawString(NameTable, myfont, Brushes.MediumBlue,left,top);
            }
        }

        private void InitializeComponent()
        {
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            this.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
            this.ResumeLayout(false);

        }
    }
}
